<template>
  <div class="list-table">
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('企业名称')" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          :placeholder="$t('企业名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('成立日期')" prop="estiblishDateArray">
        <DatePicker
          v-model="estiblishDateArray"
          type="daterange"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">
          {{ $t('搜索') }}
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['gp:managementFunds:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="gpManagementFundsList" border>
      <el-table-column
        :label="$t('序号')"
        type="index"
        align="center"
        show-overflow-tooltip
        width="50"
      >
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('企业名称')" align="center" prop="companyName">
        <template slot-scope="scope">
          <div style="display: flex;align-items: center;">
            <img v-if="scope.row.companyLogo" :src="scope.row.companyLogo" width="35" height="35" style="border-radius: 50%; " @error="scope.row.companyLogo = ''">
            <el-link type="primary" class="link_a" style="padding-left:5px;" @click="updateHandle(scope.row)">{{ scope.row.companyName }}</el-link>
          </div>
        </template>
      </el-table-column>
      <el-table-column :label="$t('法定代表人')" align="center" prop="legalName">
        <template slot-scope="scope">
          <div style="display: flex;align-items: center;">
            <img v-if="scope.row.legalLogo" :src="scope.row.legalLogo" width="35" height="35" style="border-radius: 50%; ">
            <el-link :underline="false" style="padding-left:5px;">{{ scope.row.legalPerson }}</el-link>
          </div>
        </template>
      </el-table-column>
      <el-table-column :label="$t('企业简称')" align="center" prop="companyAlias" />
      <el-table-column :label="$t('成立日期')" align="center" prop="estiblishDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.estiblishDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('注册资金')" align="center" prop="regCapital" width="120" />
      <el-table-column :label="$t('法人类型')" align="center" prop="legalPersonType" :formatter="legalPersonTypeFormat" width="120" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['gp:managementFunds:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}
          </el-button>
          <el-button
            v-hasPermi="['gp:managementFunds:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改参股基金-管理基金对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <gpManagementFundsForm ref="gpManagementFundsForm" />
    </el-dialog>
  </div>
</template>

<script>
import { delGpManagementFunds, listGpManagementFunds } from '@/api/fund/gp/tycInvest/gpManagementFunds'
import gpManagementFundsForm from './gpManagementFundsForm.vue'
import moment from 'moment'

export default {
  components: {
    gpManagementFundsForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 参股基金-管理基金表格数据
      gpManagementFundsList: [],
      // 弹出层标题
      title: '参股基金-管理基金',
      // 是否显示弹出层
      formOpen: false,
      // 法人类型字典
      legalPersonTypeOptions: [],
      // 查询参数
      queryParams: {
        gpId: this.$route.query.gpId,
        companyName: undefined,
        estiblishDateStart: undefined,
        estiblishDateEnd: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 查询参数 时间数组
      estiblishDateArray: []
    }
  },
  created() {
    this.getList()
    this.getDicts('legal_person_type').then(response => {
      this.legalPersonTypeOptions = response.data
    })
  },
  methods: {
    /** 查询参股基金-管理基金列表 */
    getList() {
      this.loading = true
      if (this.estiblishDateArray !== undefined) {
        if (this.estiblishDateArray[0] !== null && this.estiblishDateArray[0] !== undefined) {
          this.queryParams.estiblishDateStart = moment(this.estiblishDateArray[0]).format('YYYY-MM-DD')
        }
        if (this.estiblishDateArray[1] !== null && this.estiblishDateArray[1] !== undefined) {
          this.queryParams.estiblishDateEnd = moment(this.estiblishDateArray[1]).format('YYYY-MM-DD')
        }
      }
      listGpManagementFunds(this.queryParams).then(response => {
        this.gpManagementFundsList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 法人类型字典翻译
    legalPersonTypeFormat(row) {
      return this.selectDictLabel(this.legalPersonTypeOptions, row.legalPersonType)
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        gpId: this.$route.query.gpId,
        estiblishDate: undefined,
        companyLogo: undefined,
        companyAlias: undefined,
        companyName: undefined,
        legalPerson: undefined,
        legalPersonType: undefined,
        regCapital: undefined,
        legalLogo: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.estiblishDateArray = []
      this.queryParams.estiblishDateEnd = undefined
      this.queryParams.estiblishDateStart = undefined
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.gpManagementFundsForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.gpManagementFundsForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delGpManagementFunds(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    }
  }
}
</script>
